package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CollectionMemberInfoBean;
import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.MemberInfoDto;
import com.shop2cn.iapi.member.parameter.QueryMemberByDsIdBean;
import com.shop2cn.iapi.member.service.QueryMemberByDsIdCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.utils.TestDataManager;
/**
*根据分销员ID查询会员信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryMemberByDsId{
	private static QueryMemberByDsIdBean querymemberbydsidBean;
	private static QueryMemberByDsIdCall querymemberbydsidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据分销员ID查询会员信息");
	}

	@Before
	public void caseUp() {
		querymemberbydsidBean=new QueryMemberByDsIdBean();
		querymemberbydsidCall=new QueryMemberByDsIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querymemberbydsidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberByDsId_001() {
		Logger.start(true,"根据分销员ID查询会员信息成功");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			Integer csid=1;
			GodMemberService.bindMobile(shopid, userId, mobile,csid);
			
			querymemberbydsidBean.setDsId(duserId);
			querymemberbydsidCall.setData(querymemberbydsidBean);
			querymemberbydsidCall.callService();			
			Logger.verifyEquals("200", querymemberbydsidCall.getString("code"), "验证code");
			MemberInfoDto info = querymemberbydsidCall.getMemberInfoDto();
			Logger.verifyEquals(mid, info.getMemberId(), "验证getMemberId");
			Logger.verifyEquals(userId, info.getUserId(), "验证userId");
			Logger.verifyEquals(mobile, info.getMobile(), "验证mobile");
			Logger.verifyEquals(usercreateBean.getNickname(), info.getNickName(), "验证nickName");
			Logger.verifyEquals(duserId, info.getDsId(), "验证dsId");
			Logger.verifyEquals(csid, info.getCsId(), "验证CsId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberByDsId_002() {
		Logger.start(true,"不输入dsid失败");
		try {
			querymemberbydsidCall.setData(querymemberbydsidBean);
			querymemberbydsidCall.callService();			
			Logger.verifyEquals("400", querymemberbydsidCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberByDsId_003() {
		Logger.start(true,"输入dsid不存在失败");
		try {
			querymemberbydsidBean.setDsId(1);
			querymemberbydsidCall.setData(querymemberbydsidBean);
			querymemberbydsidCall.callService();			
			Logger.verifyEquals("200", querymemberbydsidCall.getString("code"), "验证code");
			Logger.verifyIsNull(querymemberbydsidCall.getMemberInfoDto(), "不会查出数据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberByDsId_004() {
		Logger.start(true,"根据分销员ID查询会员信息成功-绑定多个的情况下查询最早的");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			UserCreateBean usercreateBean2= DGUserCallService.initUsercreateBean();
			int userId2=DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid,userId2,usercreateBean2.getOpenId());
			//60.小程序 61.h5
			createMem2.setAccessSource(1);
			String mid2 = GodMemberService.creatememberCall(createMem2);
			Integer csid=1;
			GodMemberService.bindMobile(shopid, userId, mobile,1);
			GodMemberService.bindMobile(shopid, userId2, mobile);
			
			querymemberbydsidBean.setDsId(duserId);
			querymemberbydsidCall.setData(querymemberbydsidBean);
			querymemberbydsidCall.callService();			
			
			Logger.verifyEquals("200", querymemberbydsidCall.getString("code"), "验证code");
			MemberInfoDto info = querymemberbydsidCall.getMemberInfoDto();
			Logger.verifyEquals(mid, info.getMemberId(), "验证getMemberId");
			Logger.verifyEquals(userId, info.getUserId(), "验证userId");
			Logger.verifyEquals(mobile, info.getMobile(), "验证mobile");
			Logger.verifyEquals(usercreateBean.getNickname(), info.getNickName(), "验证nickName");
			Logger.verifyEquals(duserId, info.getDsId(), "验证dsId");
			Logger.verifyEquals(csid, info.getCsId(), "验证CsId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberByDsId_005() {
		Logger.start(true,"根据分销员ID查询会员信息成功-收集信息数据正确");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			Integer csid=1;
			GodMemberService.bindMobile(shopid, userId, mobile,csid);
			
			CollectionMemberInfoBean collectionmemberinfoBean=new CollectionMemberInfoBean();
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setRealName("rname");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setWechatName("wxname");
			GodMemberService.collectionmemberinfoCall(collectionmemberinfoBean);
			
			querymemberbydsidBean.setDsId(duserId);
			querymemberbydsidCall.setData(querymemberbydsidBean);
			querymemberbydsidCall.callService();			
			Logger.verifyEquals("200", querymemberbydsidCall.getString("code"), "验证code");
			MemberInfoDto info = querymemberbydsidCall.getMemberInfoDto();
			Logger.verifyEquals(mid, info.getMemberId(), "验证getMemberId");
			Logger.verifyEquals(userId, info.getUserId(), "验证userId");
			Logger.verifyEquals(mobile, info.getMobile(), "验证mobile");
			Logger.verifyEquals(usercreateBean.getNickname(), info.getNickName(), "验证nickName");
			Logger.verifyEquals(duserId, info.getDsId(), "验证dsId");
			Logger.verifyEquals(csid, info.getCsId(), "验证CsId");
			
			Logger.verifyEquals(collectionmemberinfoBean.getSex(), info.getSex(), "验证sex");
			Logger.verifyEquals(collectionmemberinfoBean.getRealName(), info.getRealName(), "验证realName");
			Logger.verifyEquals(collectionmemberinfoBean.getWechatName(), info.getWechatName(), "验证wechatName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}